<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        body {
            margin: 0;
            padding: 0;
            background-color: #F7F7F7;;
        }
        .tabs {
            width: 400px;
            margin: 30px auto;
            background-color: #FFF;
            line-height: 40px;
            overflow: hidden;
            border: 5px solid #C0DCC0;
            box-sizing: border-box;

        }
        .tabs nav {
            height: 40px;
            text-align: center;
            line-height: 40px;
            overflow: hidden;
            background-color: hsl(120, 86%, 54%);
            display: flex;
        }
        nav a {
            display: block;
            width: 100px;
            line-height: 40px;
            overflow: hidden;
            background-color: #C0DCC0;
            text-decoration: none;
        }

         nav a:last-child {
            border-right: 0 none;
        }

        nav a.active {
            background-color: #9BAF9B;
        }
        .cont {
            overflow: hidden;
            display: none;
        }

        .cont ol {
            line-height: 30px;
        }
    </style>  
</head>
<body>
    <div class="tabs">
        <nav>
            <a href="#" data-cont="local">国外新闻</a>
            <a href="#" data-cont="global">国内新闻</a>
            <a href="#" data-cont="sports">体育新闻</a>
        </nav>
        <section class="cont" id="local">   
            <ol>
                <li>国外新闻1</li>
                <li>国外新闻2</li>
                <li>国外新闻3</li>
                <li>国外新闻4</li>
            </ol>
        </section>
        <section class="cont" id="global">   
            <ol>
                <li>国内新闻1</li>
                <li>国内新闻2</li>
                <li>国内新闻3</li>
                <li>国内新闻4</li>
            </ol>
        </section>
        <section class="cont" id="sports">   
            <ol>
                <li>体育新闻1</li>
                <li>体育新闻2</li>
                <li>体育新闻3</li>
                <li>体育新闻4</li>
            </ol>
        </section>
    </div>
    <script>
        (function(key) {
           var navs = document.querySelectorAll('nav a');
           for (var i = 0; i < navs.length; i++) {
                    if (key == i) {
                        navs[i].classList.add('active');
                        var secId = navs[i].dataset['cont'];
                        alert(secId);
                        document.querySelector('#' + secId).style.display = 'block';
                    }
                
                    navs[i].onclick = function() {
                        var currentNav = document.querySelector('.active');
                        // 获取对应的内容区域 ，让其隐藏
                        var currentId = currentNav.dataset['cont'];
                        currentNav.classList.remove('active');
                         // 对应的内容区域
                         document.querySelector('#' + currentId).style.display = 'none';
                            // 突出显示自己 导航添加样式  对应的section 显示
                            // 给自己添加active样式
                            this.classList.add('active');
                           // 对应的section模块显示出来
                            var myId = this.dataset['cont'];
                                // 对应的内容区域
                         document.querySelector('#' + myId).style.display = 'block';
                    }
            }
        
        })(0);
    </script>
</body>
</html>